﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Web.UI;

namespace OMSReportViewer
{
    public static class DatabaseDAO
    {
        private static SqlConnection m_sqlConnection = null;

        public static bool Connect(string strConnectionString)
        {
            bool bSuccess = false;
            try
            {
                m_sqlConnection = new SqlConnection(strConnectionString);
                m_sqlConnection.Open();
                bSuccess = m_sqlConnection.State == System.Data.ConnectionState.Open;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return bSuccess;
        }

        public static bool Disconnect()
        {
            bool bSuccess = false;
            try
            {
                m_sqlConnection.Close();
                bSuccess = m_sqlConnection.State == System.Data.ConnectionState.Closed;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return bSuccess;
        }

        public static SqlDataReader ExecuteQuery(string strQuery)
        {
            SqlDataReader results = null;

            SqlCommand cmd = new SqlCommand(strQuery, m_sqlConnection);
            results = cmd.ExecuteReader();

            return results;
        }
    }
}